using Microsoft.AspNetCore.Mvc.Filters;
using Vin.Extension.JwtBearer.Tool;

namespace Vin.Extension.JwtBearer.Attributes;

public class VinJwtParseAuthorizeAttribute : VinJwtAuthorizeAttribute
{
    public override void OnAuthorization(AuthorizationFilterContext context)
    {
        if (context.HttpContext.User.Identity?.IsAuthenticated == true)
        {
            var model = VinSecurityTool.GetTokenModelByToken(TokenPrefix);
            if (model != null)
            {
                // 判断是否有不在token中的claim
                context.HttpContext.AddClaimsToHttpContext(model.Claims);
            }
        }
    }
}